<template>
	

  <view class="login-container">
    <view class="input-group">
      <input v-model="username" placeholder="请输入用户名" class="input" />
    </view>
    <view class="input-group">
      <input v-model="password" type="password" placeholder="请输入密码" class="input" />
    </view>
    <view class="btn-container">
      <button @click="login" class="button">登录</button>
    </view>
    <view class="register-link">
      <text @click="goToRegister">还没有账号？去注册</text>
    </view>
  </view>
</template>

<script>
	import common from  "../common/js/common.js";
	export default {
	  data() {
		return {
		  username: '',
		  password: ''
		};
	  },
	  methods: {
		login() {
		  // 保存用户信息到 localStorage
		  const userInfo = {
			  action: 'login',
			username: this.username,
			password: this.password
		  };
		uni.request({
				url: common.baseurl + '/api/user/info',
				method:'POST',
				data: userInfo,
			}).then(data=>{
				if(undefined != data[1].data.errCode){
					uni.showToast({
					          title: data[1].data.errMsg,
					          icon: 'none',
					        });
				}else{
					console.info(data[1].data)
					uni.setStorageSync('userInfo', JSON.stringify(data[1].data));
					console.log("222");
					  uni.switchTab({
						url: '/pages/ship_baidu'
					  });
				}

			}).catch(()=>{
  
			})
		 
		},
		
		goToRegister(){
		  uni.redirectTo({
			url: '/pages/register'
		  });
		}
		
	  }
	};
</script>



<style scoped>
.login-container {
  padding: 30px;
}
.input-group {
  margin-bottom: 20px;
}
.input {
  width: 100%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
}
.button {
  width: 100%;
  background-color: #007AFF;
  color: white;
  border-radius: 5px;
  border: none;
  font-size: 16px;
}
.register-link {
  margin-top: 10px;
  text-align: center;
}
.register-link text {
  color: #007AFF;
}
</style>
